import {ActionType, ProColumns, ProTable,} from '@ant-design/pro-components';
import React, {useRef, useState} from 'react';
import {getSearch} from "@/services/Admin/orderManage";

export const waitTimePromise = async (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

/**
 * 订单管理页面
 * @constructor
 */
const OrderUserPage: React.FC<unknown> = () => {
  // @ts-ignore
  const [data, setData] = useState<Admin.PageQueryVO<Admin.Order>>({});
  const actionRef = useRef<ActionType>();

  /**
   * 表格列配置
   */
  const columns: ProColumns<Admin.Order>[] = [
    {
      dataIndex: 'id',
      valueType: 'indexBorder',
      width: 48,
    },
    {
      title: '订单编号',
      dataIndex: 'orderId',
    },
    {
      title: '商品名称',
      dataIndex: 'goodsName',
      search: false,
    },
    {
      title: '购买用户',
      dataIndex: 'userAccount',
      search: false,
    },
    {
      title: '账户状态',
      dataIndex: 'orderStatus',
      valueType: 'select',
      valueEnum: {
        0: {
          text: '完成',
          status: 'Success'
        },
        1: {
          text: '下单',
          status: 'Success'
        },
        2: {
          text: '商家已确定发货',
          status: 'Success'
        },
      }
    },
    {
      title: '下单时间',
      dataIndex: 'checkoutTime',
      valueType: 'dateTime',
      search: false,
    },
  ];


  return (
    <>
      <ProTable<Admin.Order>
        headerTitle="订单管理"
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 'auto',
        }}
        pagination={
          {
            pageSize:8,
            total:data.total
          }
        }
        onChange={()=>{
          console.log('aaa')
        }}
        request={async (params, sorter, filter) => {
          const res=await getSearch({...params} as Admin.OrderQueryParams);
          setData(res);
          return {
            data: res.list || [],
          } as any;
        }}
        columns={columns}
      />
    </>
  );
};

export default OrderUserPage;
